# conftest.py
import pytest
from utils.request_util import message_host_qa, Request


@pytest.fixture
def base_headers():
    """
    基础请求头fixture: 获取所有接口所需的基础请求头
    """
    headers = {
        "X-Product-Id": "427333",
        "X-Access-Key": "38c6c8f5aca9485e",
        "App-Id": "1000040"
    }
    return headers
@pytest.fixture
def fresh_token(base_headers):
    """
    全局fixture: 每次调用都返回新的token
    function作用域确保每次测试都获取新token
    """
    url = message_host_qa + "/service/message/inner/v1/token/getToken"
    res = Request().post(url = url,headers = base_headers)
    assert res.status_code == 200, f"获取token失败，状态码: {res.status_code}"

    token = res.json()
    assert token, "token不能为空"

    return token

